package com.jubao.ejb.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.jubao.ejb.entity.callback.GeneEntityCallbackListener;

//@MappedSuperclass
@Entity
@Table(name = "geneentity_tbl", schema = "jubao_database", uniqueConstraints = {})
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@EntityListeners(GeneEntityCallbackListener.class)
@TableGenerator(name = "entity_sys_id", table = "entity_primary_key", pkColumnName = "pk", pkColumnValue = "sysid", valueColumnName = "pkvalue", allocationSize = 10)
//@SequenceGenerator(name = "entity_sequence", sequenceName = "entity_id_seq")
@NamedQueries( {
		@NamedQuery(name = "BrandDao.eql.findBrandById", query = "SELECT x FROM Brand x WHERE x.id=:brandId"),
		@NamedQuery(name = "CategoryDao.eql.findCategoryById", query = "SELECT x FROM Category x WHERE x.id=:categoryId"),
		@NamedQuery(name = "CategoryDao.eql.getChildCategoryListByParentId", query = "SELECT x FROM Category x WHERE x.primaryParent.id=:parentCategoryId"),
		@NamedQuery(name = "CategoryDao.eql.getChildCategoryListByParentSysId", query = "SELECT x FROM Category x WHERE x.primaryParent.sysId=:parentCategorySysId"),
		@NamedQuery(name = "CategoryDao.eql.getChildCategoryCountByParentSysId", query = "SELECT count(x) FROM Category x WHERE x.primaryParent.sysId=:parentCategorySysId"),

		@NamedQuery(name = "ProductDao.eql.findProductById", query = "SELECT x FROM Product x WHERE x.id=:id"),
		@NamedQuery(name = "ProductDao.eql.getProductCountBySupplierSysId", query = "SELECT count(x) FROM Product x WHERE x.supplier.sysId=:supplierSysId "),
		@NamedQuery(name = "ProductDao.eql.getProductListBySupplierSysId", query = "SELECT x FROM Product x WHERE x.supplier.sysId=:supplierSysId ORDER BY x.rank desc, x.createdDate DESC"),

		@NamedQuery(name = "StoreDao.eql.findStoreById", query = "SELECT x FROM Store x WHERE x.id=:id"),

		@NamedQuery(name = "StoreTransactionDao.eql.findLatestTransactionByStoreSysId", query = "SELECT x FROM StoreTransaction x WHERE x.store.sysId=:storeSysId ORDER BY x.sysId DESC"),
		@NamedQuery(name = "StoreTransactionDao.eql.getStoreTransactionCountByStoreSysId", query = "SELECT count(x) FROM StoreTransaction x WHERE x.store.sysId=:storeSysId"),
		@NamedQuery(name = "StoreTransactionDao.eql.getStoreTransactionListByStoreSysId", query = "SELECT x FROM StoreTransaction x WHERE x.store.sysId=:storeSysId ORDER BY x.sysId DESC"),		
		
		@NamedQuery(name = "CouponDao.eql.findCouponById", query = "SELECT x FROM Coupon x WHERE x.id=:id"),
		@NamedQuery(name = "CouponDao.eql.findCouponItemById", query = "SELECT x FROM CouponItem x WHERE x.id=:id"),
		@NamedQuery(name = "CouponDao.eql.getCouponCountByStoreSysId", query = "SELECT count(x) FROM Coupon x WHERE x.store.sysId=:storeSysId"),
		@NamedQuery(name = "CouponDao.eql.getCouponListByStoreSysId", query = "SELECT x FROM Coupon x WHERE x.store.sysId=:storeSysId"),

		@NamedQuery(name = "WebsiteDao.eql.findWebsiteById", query = "SELECT x FROM Website x WHERE x.id=:id"),
		@NamedQuery(name = "UserWebsiteDao.eql.getUserWebsiteListByUserSysId", query = "SELECT x FROM UserWebsite x WHERE x.user.sysId=:userSysId"),

		@NamedQuery(name = "WebsiteDao.eql.getWebsiteListByStatus", query = "SELECT x FROM Website x WHERE x.status=:status"),
		@NamedQuery(name = "WebsiteDao.eql.getWebsiteCountByStatus", query = "SELECT count(x) FROM Website x WHERE x.status=:status"),

		
		@NamedQuery(name = "UserDao.eql.findUserById", query = "SELECT x FROM User x WHERE x.id=:id") })
public class GeneEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -168544564797933101L;

	@Id
	//@GeneratedValue(strategy = GenerationType.SEQUENCE) //not work
	//@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "entity_sequence") //not work for hibernate dialet of mysql not support sequence
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "entity_sys_id")
	//worked
	private Long sysId;

	private Integer status;

	private Integer rank = new Integer(0);

	private Long createdDate;

	private Long lastUpdatedDate;

	public Long getSysId() {
		return sysId;
	}

	public void setSysId(Long sysId) {
		this.sysId = sysId;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getRank() {
		return rank;
	}

	public void setRank(Integer rank) {
		this.rank = rank;
	}

	public long getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(long createdDate) {
		this.createdDate = createdDate;
	}

	public long getLastUpdatedDate() {
		return lastUpdatedDate;
	}

	public void setLastUpdatedDate(long lastUpdatedDate) {
		this.lastUpdatedDate = lastUpdatedDate;
	}

}
